<?php
/*
 Plugin Name: Aonz Opengraph
Plugin URI: 
Description: Aonz Opengraph
Version: 1.0
Author: AonzZung
Author URI: 
License: A "Slug" license name e.g. GPL2
*/
?>
<?php 

/**
 * class AonzOpenGraph
 */
class AonzOpenGraph
{
	/**
	 * Plugin Folder
	 * @access protected
	 * @var string
	 */
	protected $plugin_folder = null;

	/**
	 * Plugin Directory
	 * @access protected
	 * @var string
	 */
	protected $plugin_dir = null;

	/**
	 * Plugin Url
	 * @access protected
	 * @var string
	 */
	protected $plugin_url = null;

	/**
	 * Plugin File
	 * @access protected
	 * @var string
	 */
	protected $plugin_file = null;
	
	/**
	 * Constructor
	 * Do nothing
	 * @access public
	 */
	public function __construct()
	{
	} // function construct()
	
	public function init()
	{
		$this->plugin_folder = substr(dirname(__FILE__), strrpos(dirname(__FILE__), DIRECTORY_SEPARATOR) + 1);
		$this->plugin_url = WP_PLUGIN_URL . '/' . $this->plugin_folder;
		$this->plugin_dir = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $this->plugin_folder;
		$this->plugin_file = $this->plugin_folder . '/' . basename(__FILE__);
		
		// adding the refresh javascript file
		wp_enqueue_script( 'aonz-opengraph-js', $this->plugin_url . '/aonz-opengraph.js', array( 'jquery' ) );
		
		//Init actions
		add_action('bp_activity_post_form_options', array($this, 'init_facebook_switch_button'));
		
		// add method publish_og_action to action hook wp_ajax_publish_og_action
		// 		add_action('bp_activity_posted_update', array($this, 'publish_og_action'));
		add_action('wp_ajax_publish_og_action', array($this, 'publish_og_action'));
		
		//Add activity after comment post
		add_action('wp_ajax_add_activity_for_comment_post', array($this, 'add_activity_for_comment_post'));
	}
	
	function init_facebook_switch_button()
	{
		echo "<b>Test Aonz</b>";
		error_log("Aonz - init_facebook_switch_button");
	}
	
	function publish_og_action()
	{
// 		echo "current_page_url=".$_POST['current_page_url'];
		error_log("Aonz - publish_og_action ".$current_page_url);
		
		//TODO Publish OG here
		
		//Update activity meta
		//$meta_key_post_id = $_POST['meta_key_post_id'];
		
	}
}

function aonz_og_init()
{
	$aonzOG = new AonzOpenGraph();
	$aonzOG->init();
}

function add_activity_for_comment_post()
{
	//*** Add comment post activity already exist functionality
// 	global $post;
// 	$content = $_POST['content'];
// 	// Now write the values
// 	// Record this on the user's profile
// 	$user_id = bp_loggedin_user_id();
// 	$from_user_link   = bp_core_get_userlink( $user_id );
// 	$activity_action  = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link );
// 	$activity_content = $content;
// 	$primary_link     = bp_core_get_userlink( $user_id, false, true );

// 	// Now write the values
// 	$activity_id = bp_activity_add( array(
// 		'user_id'      => $user_id,
// 		'action'       => apply_filters( 'bp_activity_new_update_action', $activity_action ),
// 		'content'      => apply_filters( 'bp_activity_new_update_content', $activity_content ),
// 		'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
// 		'component'    => $bp->activity->id,
// 		'type'         => 'activity_comment_post'
// 	) );
	
// 	bp_activity_update_meta($activity_id, "post_id", $post->ID );
}

add_action('after_setup_theme', 'aonz_og_init');
?>